package written.test;

import edu.princeton.cs.algs4.In;

import java.util.*;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/1  20:07
 * @Description:
 */
public class Main9 {
    static Map<Integer, Integer> expect = new HashMap<>();
    static List<List<Integer>> packages = new ArrayList<>();
    static int ans = Integer.MAX_VALUE;
    static int n;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = Integer.parseInt(sc.nextLine());
        String[] s1 = sc.nextLine().split(" ");
        String[] s2 = sc.nextLine().split(" ");
        String[] s3 = sc.nextLine().split(" ");

        for(int i = 0; i < s3.length; i++){
            expect.put(Integer.parseInt(s3[i]), 0);
        }
        expect.put(n+1, s3.length);
        expect.put(n+2, 0);
        for(int i = 0; i < s1.length; i++){
            String[] split = s1[i].split(",");
            List<Integer> temp = new ArrayList<>();
            for(String s: split){
                temp.add(Integer.parseInt(s));
            }
            temp.add(Integer.parseInt(s2[i]));
            packages.add(temp);
        }
        backup(0);
        System.out.println(ans);
    }
    public static void backup(int index){
        if(expect.get(n+1) != 0){
            if(index >= packages.size()) return;

            Map<Integer, Integer> tmap = new HashMap<>(expect);
            List<Integer> temp = packages.get(index);

            for(int i = 0; i < temp.size()-1; i++){
                Integer t = temp.get(i);
                if(expect.get(t)!=null){
                    if(expect.get(t) < 1){
                        expect.put(n+1, expect.get(n+1)-1);
                    }
                    expect.put(t, expect.get(t)+1);
                }
            }
            expect.put(n+2, expect.get(n+2) + temp.get(temp.size()-1));
            backup(index+1);
            expect = tmap;
            backup((index+1));
        }else{
            ans = Math.min(ans, expect.get(n+2));
            return;
        }
    }
}
